package org.dromara.admin.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.admin.domain.vo.GeneralConfigVo;
import org.dromara.admin.domain.bo.GeneralConfigBo;
import org.dromara.admin.service.IGeneralConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 后台租房通用配置
 *
 * @author Lion Li
 * @date 2025-09-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/all/generalConfig")
public class AdminGeneralConfigController extends BaseController {

    private final IGeneralConfigService generalConfigService;

    /**
     * 查询租房通用配置列表
     */
//    @SaCheckPermission("all:generalConfig:list")
    @GetMapping("/list")
    public TableDataInfo<GeneralConfigVo> list(GeneralConfigBo bo, PageQuery pageQuery) {
        return generalConfigService.queryPageList(bo, pageQuery);
    }


    /**
     * 查询全部户型列表
     * @return
     */
    @GetMapping("/layoutList")
    public TableDataInfo<GeneralConfigVo> layoutList(PageQuery pageQuery) {
        return generalConfigService.queryPageLayoutList(pageQuery);
    }

    /**
     * 查询全部电器列表
     */
    @GetMapping("/electricalList")
    public R<List<GeneralConfigVo>> electricalList() {
        return R.ok(generalConfigService.queryElectricalList());
    }

    /**
     * 导出租房通用配置列表
     */
//    @SaCheckPermission("all:generalConfig:export")
    @Log(title = "租房通用配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GeneralConfigBo bo, HttpServletResponse response) {
        List<GeneralConfigVo> list = generalConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "租房通用配置", GeneralConfigVo.class, response);
    }

    /**
     * 获取租房通用配置详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("all:generalConfig:query")
    @GetMapping("/{id}")
    public R<GeneralConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(generalConfigService.queryById(id));
    }

    /**
     * 新增租房通用配置
     */
//    @SaCheckPermission("all:generalConfig:add")
    @Log(title = "租房通用配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GeneralConfigBo bo) {
        return toAjax(generalConfigService.insertByBo(bo));
    }

    /**
     * 修改租房通用配置
     */
//    @SaCheckPermission("all:generalConfig:edit")
    @Log(title = "租房通用配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GeneralConfigBo bo) {
        return toAjax(generalConfigService.updateByBo(bo));
    }

    /**
     * 删除租房通用配置
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("all:generalConfig:remove")
    @Log(title = "租房通用配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(generalConfigService.deleteWithValidByIds(List.of(ids), true));
    }
}
